#!/bin/bash

# 查找正在运行的Java进程的PID
JAVA_PROCESS_PID=$(ps aux | grep 'java -jar run-fudao-1.0.0-SNAPSHOT.jar' | grep -v grep | awk '{print \$2}')

if [ -z "$JAVA_PROCESS_PID" ]; then
    echo "No existing Java process found."
else
    echo "Stopping existing Java process with PID $JAVA_PROCESS_PID..."
    kill $JAVA_PROCESS_PID
    sleep 2 # 等待2秒确保进程被终止
    echo "Java process with PID $JAVA_PROCESS_PID stopped."
fi

# 启动新的Java进程
echo "Starting Java process..."
nohup java -jar run-fudao-1.0.0-SNAPSHOT.jar 2>&1 &

echo "Java process started."
